<?php
class Cl_UserAttend extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$user_attend_seq		= 0		,	//	출석체크 키값
		$user_attend_date		= ''	,	//	출석 체크 날짜
		$user_seq				= 0		,	//	사용자 키값
		$user_attend_memo		= ''	,	//	메모사항
		$user_attend_point		= 0		,	//	획득 포인트
		$user_attend_continue	= 0		,	//	개근
		$user_attend_time		= 0		,	//	등록시간
		/******************************************************/
		//	추가 정보
		/******************************************************/
		$user_name					= ''	,	//	
		$user_login_id				= ''	,	//	
		$user_icon					= ''	,	//	
		$user_nick					= ''	,	//	
		$user_nick_str				= ''	,	//	
		$user_attend_time_str		= ''	;	//	
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($user_attend_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($user_attend_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		$this->user_nick_str = $this->user_nick;
		if($this->user_icon)
		{
			$this->user_nick_str = "<img src='{$this->user_icon}' class='user_icon'/>";
		}
		$this->user_attend_time_str = parent::timeString($this->user_attend_time);
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$this->user_attend_date		= date('Y-m-d');
		$this->user_attend_time		= time();
		$this->user_attend_continue	= $dbo->getLast($this->user_seq);
		$this->cal_point();
		
		$data = array(	'user_attend_date'		=>	$this->user_attend_date,
						'user_seq'				=>	$this->user_seq,
						'user_attend_date'		=>	$this->user_attend_date,
						'user_attend_memo'		=>	$this->user_attend_memo,
						'user_attend_point'		=>	$this->user_attend_point,
						'user_attend_continue'	=>	$this->user_attend_continue,
						'user_attend_time'		=>	$this->user_attend_time
					);
		$this->user_attend_seq = $dbo->insert($data);
		$up = Wdk::get('UserPoint');
		$up->plus(	$this->user_seq,
					$this->user_attend_point,
					"[출석포인트] {$this->user_attend_continue} 일 개근"
					);
	}
	
	/**
	 *	
	 */
	private function cal_point()
	{
		$ss = Wdk::get('SettingsManager');
		$settings = $ss->data();
		$point1 = (int) (isset($settings['user_attend_point']) ? $settings['user_attend_point'] : 5);
		$point2 = (int) (isset($settings['user_attend_continue_point']) ? $settings['user_attend_continue_point'] : 0);
		$this->user_attend_point	= $point1 + ($this->user_attend_continue - 1) * $point2;
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		throw new MethodNotImplementedException("업데이트 기능은 제공하지 않습니다.");
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		throw new MethodNotImplementedException("삭제 기능은 제공하지 않습니다.");
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		throw new MethodNotImplementedException("backup 기능은 제공하지 않습니다.");
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}